﻿using AnesSystem.Models;
using AnesSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnesSystem.Controls
{
    /// <summary>
    /// ContinueEventEditCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class ContinueEventEditCtrl : UserControl
    {
        public ContinueEventEditCtrl()
        {
            InitializeComponent();
            this.DataContext = ContinueEventEditViewModel.Instance;

        }

        public PatientEventsModel PatientEvent
        {
            get
            {
                return ContinueEventEditViewModel.Instance.PatientEvent;
            }
            set
            {
                ContinueEventEditViewModel.Instance.PatientEvent = value;
            }
        }

        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox checkBox = sender as CheckBox;
            ContinueEventEditViewModel.Instance.UpdateEndTime((bool)checkBox.IsChecked);
            ContinueEventEditViewModel.Instance.RefreshWin();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;
            string tag = button.Tag.ToString();
            String result = Constants.FAILED;
            switch (tag)
            {
                case "Save":
                    result = ContinueEventEditViewModel.Instance.Save();
                    if (result.Equals(Constants.SUCCESS))
                    {
                        ContinueEventEditViewModel.Instance.RefreshWin();
                        DrugAndEventWindow.Instance.CloseWin(false);
                    }
                    break;
                case "Cancel":
                    DrugAndEventWindow.Instance.CloseWin(false);
                    break;
                case "DelEvent":
                    result = ContinueEventEditViewModel.Instance.DelEvent();
                    if (result.Equals(Constants.SUCCESS))
                    {
                        ContinueEventEditViewModel.Instance.RefreshWin();
                        DrugAndEventWindow.Instance.CloseWin(false);
                    }
                    break;
            }

        }
    }
}
